'''
Author: duliang thinktanker@163.com
Date: 2024-06-25 23:09:28
LastEditors: duliang thinktanker@163.com
LastEditTime: 2024-07-08 23:43:37
FilePath: 
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import numpy as np
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
# from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
# with open('temp.txt', 'r') as f:
#     data = f.read().splitlines()
#     # data = [int(i) for i in data]
# # 数据序列
# data = np.array(data, dtype=float)
# 数据序列
data = np.array([
    18.93, 18.92, 18.91, 18.91, 18.93, 18.93, 18.93, 18.93, 18.92, 18.91, 18.9,
    18.92, 18.91, 18.89, 18.9, 18.9
])

# 将数据转换为Pandas Series以方便操作
series = pd.Series(data)

# 可视化ACF和PACF图帮助选择p和q的值
# plot_acf(series)
# plot_pacf(series)
# 注意：在实际操作中，您可能需要查看这些图表来决定ARIMA模型的参数p, d, q，这里为了简化直接设定

# 定义ARIMA模型的参数，这里假设d=1（需要差分使序列平稳），p和q根据ACF和PACF图决定，这里作为示例直接设定
p = 1  # 自回归项的阶数
d = 1  # 差分的阶数，用于消除趋势
q = 1  # 移动平均项的阶数

# 创建并训练ARIMA模型
model = ARIMA(series, order=(p, d, q))
model_fit = model.fit()

# 预测接下来的3个数值
forecast = model_fit.forecast(steps=3)

print("预测的接下来3个数值：", forecast.tolist())
